package com.rfid.project.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.rfid.project.model.People;

import java.util.List;
import java.util.ArrayList;

import biz.util.StringUtil;

@Service
@Transactional
public class ProcessEngine {
	
	@Autowired
	private ProjectDelayApplyService projectDelayApplyService;
	
	
	@Autowired
	public void setProjectDelayApplyService(
			ProjectDelayApplyService projectDelayApplyService) {
		this.projectDelayApplyService = projectDelayApplyService;
	}

	@Autowired
	public void setProcessSourceForProjectDelayApply(
			ProcessSourceForProjectDelayApply processSourceForProjectDelayApply) {
		this.processSourceForProjectDelayApply = processSourceForProjectDelayApply;
	}

	@Autowired
	public void setProcessSourceForProjectFinishApply(
			ProcessSourceForProjectFinishApply processSourceForProjectFinishApply) {
		this.processSourceForProjectFinishApply = processSourceForProjectFinishApply;
	}

	
	@Autowired
	public void setProcessSourceForProjectTaskFinishApply(
			ProcessSourceForProjectTaskFinishApply processSourceForProjectTaskFinishApply) {
		this.processSourceForProjectTaskFinishApply = processSourceForProjectTaskFinishApply;
	}

	@Autowired
	public void setProcessSourceForProjectTaskDelayApply(
			ProcessSourceForProjectTaskDelayApply processSourceForProjectTaskDelayApply) {
		this.processSourceForProjectTaskDelayApply = processSourceForProjectTaskDelayApply;
	}

	@Autowired
	public void setProcessSourceForProjectMilestoneChange(
			ProcessSourceForProjectMilestoneChange processSourceForProjectMilestoneChange) {
		this.processSourceForProjectMilestoneChange = processSourceForProjectMilestoneChange;
	}

	@Autowired
	public void setProcessSourceForProjectMilestoneFinishApply(
			ProcessSourceForProjectMilestoneFinishApply processSourceForProjectMilestoneFinishApply) {
		this.processSourceForProjectMilestoneFinishApply = processSourceForProjectMilestoneFinishApply;
	}

	@Autowired
	ProcessSourceForProjectDelayApply processSourceForProjectDelayApply;

	@Autowired
	ProcessSourceForProjectFinishApply processSourceForProjectFinishApply;

	@Autowired
	ProcessSourceForProjectTaskFinishApply processSourceForProjectTaskFinishApply;
	
	@Autowired
	ProcessSourceForProjectTaskDelayApply processSourceForProjectTaskDelayApply;
	
	@Autowired
	ProcessSourceForProjectMilestoneChange processSourceForProjectMilestoneChange;

	@Autowired
	ProcessSourceForProjectDelivery processSourceForProjectDelivery;

	@Autowired
	ProcessSourceForProjectMilestoneFinishApply processSourceForProjectMilestoneFinishApply;

	//获得任务列表
	public List<Process> getCurrentTaskList(String processTypeId,String submitPersonId,People currentUser){
		List<Process> resultList = new ArrayList<Process>();
		if(StringUtil.isEmpty(processTypeId)){
			//不限定流程类型时，获得所有流程源头的流程
		
			//项目完结申请
			resultList.addAll(processSourceForProjectFinishApply.getCurrentTaskListByProcessor(currentUser));
			//项目延期申请
			resultList.addAll(processSourceForProjectDelayApply.getCurrentTaskListByProcessor(currentUser));
			//任务完结申请
			resultList.addAll(processSourceForProjectTaskFinishApply.getCurrentTaskListByProcessor(currentUser));
			//任务延期申请
			resultList.addAll(processSourceForProjectTaskDelayApply.getCurrentTaskListByProcessor(currentUser));
			//项目节点延期申请
			resultList.addAll(processSourceForProjectMilestoneChange.getCurrentTaskListByProcessor(currentUser));
			//项目节点质量审核
			resultList.addAll(processSourceForProjectMilestoneFinishApply.getCurrentQualityListByProcessor(currentUser));
			//项目节点完结申请
			resultList.addAll(processSourceForProjectMilestoneFinishApply.getCurrentTaskListByProcessor(currentUser));
			//产品交付审核
			resultList.addAll(processSourceForProjectDelivery.getCurrentTaskListByProcessor(currentUser));
		}else if(processTypeId.equals(ProcessType.PROJECT_FINISH)){
			//项目完结申请
			resultList.addAll(processSourceForProjectFinishApply.getCurrentTaskListByProcessor(currentUser));
		}else if(processTypeId.equals(ProcessType.PROJECT_DELAY)){
			//项目延期申请
			resultList.addAll(processSourceForProjectDelayApply.getCurrentTaskListByProcessor(currentUser));
		}else if(processTypeId.equals(ProcessType.PROJECT_DELIVERY_CHECK)){
			//项目交付物审核
			resultList.addAll(processSourceForProjectDelivery.getCurrentTaskListByProcessor(currentUser));
		}else if(processTypeId.equals(ProcessType.PROJECT_MILESTONE_QUALITY)){
			//项目节点完成申请质量控制
			resultList.addAll(processSourceForProjectMilestoneFinishApply.getCurrentQualityListByProcessor(currentUser));
		}else if(processTypeId.equals(ProcessType.PROJECT_MILESTONE_FINISH)){
			//项目节点完成申请
			resultList.addAll(processSourceForProjectMilestoneFinishApply.getCurrentTaskListByProcessor(currentUser));
		}else if(processTypeId.equals(ProcessType.PROJECT_MILESTONE_DELAY)){
			//项目节点延期申请
			resultList.addAll(processSourceForProjectMilestoneChange.getCurrentTaskListByProcessor(currentUser));
		}else if(processTypeId.equals(ProcessType.PROJECT_TASK_FINISH)){
			//任务完结申请
			resultList.addAll(processSourceForProjectTaskFinishApply.getCurrentTaskListByProcessor(currentUser));
		}else if(processTypeId.equals(ProcessType.PROJECT_TASK_DELAY)){
			//任务延期申请
			resultList.addAll(processSourceForProjectTaskDelayApply.getCurrentTaskListByProcessor(currentUser));
		}
		
		//获取任务审批列表
		//获取
		/*
		 * 	//项目完结流程
		public static final String PROJECT_FINISH = "0001";
		//项目延期流程
		public static final String PROJECT_DELAY = "0002";
		//项目节点完结流程
		public static final String PROJECT_MILESTONE_FINISH = "0003";
		//项目节点延期流程
		public static final String PROJECT_MILESTONE_DELAY = "0004";
		//项目任务完结流程
		public static final String PROJECT_TASK_FINISH = "0005";
		//项目任务延期流程
		public static final String PROJECT_TASK_DELAY = "0006";
		//项目交付记录审核流程
		public static final String PROJECT_DELIVERY_CHECK = "0007";
		 */
		return resultList;
	}
	
	public void getHistoryTaskList(Long userId){
		
	}
	
	
}
